// DialogPathwayGeneratorSetup.cpp : implementation file
//

#include "stdafx.h"
#include "testSVG.h"
#include "DialogPathwayGeneratorSetup.h"
#include "testSVG.h"
#include "testSVGDlg.h"
#include ".\dialogpathwaygeneratorsetup.h"

extern MOLECULE* MoleculesList;

// CDialogPathwayGeneratorSetup dialog

IMPLEMENT_DYNAMIC(CDialogPathwayGeneratorSetup, CDialog)
CDialogPathwayGeneratorSetup::CDialogPathwayGeneratorSetup(CWnd* pParent /*=NULL*/)
	: CDialog(CDialogPathwayGeneratorSetup::IDD, pParent)
{
}

CDialogPathwayGeneratorSetup::~CDialogPathwayGeneratorSetup()
{
}

void CDialogPathwayGeneratorSetup::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
}


BEGIN_MESSAGE_MAP(CDialogPathwayGeneratorSetup, CDialog)
	ON_BN_CLICKED(IDOK, OnBnClickedOk)
	ON_CBN_SELCHANGE(IDC_COMBO_SOURCE_COND1_TYPE, OnCbnSelchangeComboSourceCond1Type)
	ON_CBN_SELCHANGE(IDC_COMBO_SOURCE_COND2_TYPE, OnCbnSelchangeComboSourceCond2Type)
	ON_CBN_SELCHANGE(IDC_COMBO_SOURCE_COND3_TYPE, OnCbnSelchangeComboSourceCond3Type)
	ON_CBN_SELCHANGE(IDC_COMBO_SOURCE_COND4_TYPE, OnCbnSelchangeComboSourceCond4Type)
	ON_CBN_SELCHANGE(IDC_COMBO_TARGET_COND1_TYPE, OnCbnSelchangeComboTargetCond1Type)
	ON_CBN_SELCHANGE(IDC_COMBO_TARGET_COND2_TYPE, OnCbnSelchangeComboTargetCond2Type)
	ON_CBN_SELCHANGE(IDC_COMBO_TARGET_COND3_TYPE, OnCbnSelchangeComboTargetCond3Type)
	ON_CBN_SELCHANGE(IDC_COMBO_TARGET_COND4_TYPE, OnCbnSelchangeComboTargetCond4Type)
	ON_CBN_KILLFOCUS(IDC_COMBO_SOURCE_COND2_TYPE, OnCbnKillfocusComboSourceCond2Type)
	ON_BN_CLICKED(IDCANCEL, OnBnClickedCancel)
END_MESSAGE_MAP()


// CDialogPathwayGeneratorSetup message handlers

void CDialogPathwayGeneratorSetup::OnBnClickedOk()
{
	//save conditions and selections
	CEdit* myEdit;
	char temp[100];
	CComboBox* myCombo1;
	CComboBox* myCombo2;
	CComboBox* myCombo3;
	CComboBox* myCombo4;
	CComboBox* myCombo5;
	CComboBox* myCombo6;
	CComboBox* myCombo7;
	CComboBox* myCombo8;
	CComboBox* myCombo9;
	CComboBox* myCombo10;
	CComboBox* myCombo11;
	CComboBox* myCombo12;
	CComboBox* myCombo13;
	CComboBox* myCombo14;
	CComboBox* myCombo15;
	CComboBox* myCombo16;
	CButton* myCheck;

	myCombo1 = (CComboBox*) GetDlgItem(IDC_COMBO_SOURCE_COND1_TYPE);
	myCombo2 = (CComboBox*) GetDlgItem(IDC_COMBO_SOURCE_COND2_TYPE);
	myCombo3 = (CComboBox*) GetDlgItem(IDC_COMBO_SOURCE_COND3_TYPE);
	myCombo4 = (CComboBox*) GetDlgItem(IDC_COMBO_SOURCE_COND4_TYPE);
	myCombo5 = (CComboBox*) GetDlgItem(IDC_COMBO_SOURCE_COND1_NAME);
	myCombo6 = (CComboBox*) GetDlgItem(IDC_COMBO_SOURCE_COND2_NAME);
	myCombo7 = (CComboBox*) GetDlgItem(IDC_COMBO_SOURCE_COND3_NAME);
	myCombo8 = (CComboBox*) GetDlgItem(IDC_COMBO_SOURCE_COND4_NAME);
	myCombo9 = (CComboBox*) GetDlgItem(IDC_COMBO_TARGET_COND1_TYPE);
	myCombo10 = (CComboBox*) GetDlgItem(IDC_COMBO_TARGET_COND2_TYPE);
	myCombo11 = (CComboBox*) GetDlgItem(IDC_COMBO_TARGET_COND3_TYPE);
	myCombo12 = (CComboBox*) GetDlgItem(IDC_COMBO_TARGET_COND4_TYPE);
	myCombo13 = (CComboBox*) GetDlgItem(IDC_COMBO_TARGET_COND1_NAME);
	myCombo14 = (CComboBox*) GetDlgItem(IDC_COMBO_TARGET_COND2_NAME);
	myCombo15 = (CComboBox*) GetDlgItem(IDC_COMBO_TARGET_COND3_NAME);
	myCombo16 = (CComboBox*) GetDlgItem(IDC_COMBO_TARGET_COND4_NAME);
	myCheck = (CButton*) GetDlgItem(IDC_CHECK_DIRECT_ONLY);
	
	m_checkDirectOnly = myCheck->GetCheck();
	
	myEdit = (CEdit*) GetDlgItem(IDC_EDIT_STEPS);
	myEdit->GetWindowText(temp, 100);

	m_numberOfSteps = atoi(temp);
	

	myEdit = (CEdit*) GetDlgItem(IDC_EDIT_SIZE);
	myEdit->GetWindowText(temp, 100);

	m_maxSize = atoi(temp);

	myCombo1->GetWindowText(m_sourceCondType1);
	myCombo2->GetWindowText(m_sourceCondType2);
	myCombo3->GetWindowText(m_sourceCondType3);
	myCombo4->GetWindowText(m_sourceCondType4);
	myCombo9->GetWindowText(m_targetCondType1);
	myCombo10->GetWindowText(m_targetCondType2);
	myCombo11->GetWindowText(m_targetCondType3);
	myCombo12->GetWindowText(m_targetCondType4);

	myCombo5->GetWindowText(m_sourceCondName1);
	myCombo6->GetWindowText(m_sourceCondName2);
	myCombo7->GetWindowText(m_sourceCondName3);
	myCombo8->GetWindowText(m_sourceCondName4);
	myCombo13->GetWindowText(m_targetCondName1);
	myCombo14->GetWindowText(m_targetCondName2);
	myCombo15->GetWindowText(m_targetCondName3);
	myCombo16->GetWindowText(m_targetCondName4);

	OnOK();
}

BOOL CDialogPathwayGeneratorSetup::OnInitDialog()
{
	CDialog::OnInitDialog();
	
	int i;
	CString tempStr;
	
	CEdit* myEdit;
	CComboBox* myCombo1;
	CComboBox* myCombo2;
	CComboBox* myCombo3;
	CComboBox* myCombo4;
	CComboBox* myCombo5;
	CComboBox* myCombo6;
	CComboBox* myCombo7;
	CComboBox* myCombo8;
	CComboBox* myCombo9;
	CComboBox* myCombo10;
	CComboBox* myCombo11;
	CComboBox* myCombo12;
	CComboBox* myCombo13;
	CComboBox* myCombo14;
	CComboBox* myCombo15;
	CComboBox* myCombo16;
	CButton* myCheck;

	myCombo1 = (CComboBox*) GetDlgItem(IDC_COMBO_SOURCE_COND1_TYPE);
	myCombo2 = (CComboBox*) GetDlgItem(IDC_COMBO_SOURCE_COND2_TYPE);
	myCombo3 = (CComboBox*) GetDlgItem(IDC_COMBO_SOURCE_COND3_TYPE);
	myCombo4 = (CComboBox*) GetDlgItem(IDC_COMBO_SOURCE_COND4_TYPE);
	myCombo5 = (CComboBox*) GetDlgItem(IDC_COMBO_SOURCE_COND1_NAME);
	myCombo6 = (CComboBox*) GetDlgItem(IDC_COMBO_SOURCE_COND2_NAME);
	myCombo7 = (CComboBox*) GetDlgItem(IDC_COMBO_SOURCE_COND3_NAME);
	myCombo8 = (CComboBox*) GetDlgItem(IDC_COMBO_SOURCE_COND4_NAME);
	myCombo9 = (CComboBox*) GetDlgItem(IDC_COMBO_TARGET_COND1_TYPE);
	myCombo10 = (CComboBox*) GetDlgItem(IDC_COMBO_TARGET_COND2_TYPE);
	myCombo11 = (CComboBox*) GetDlgItem(IDC_COMBO_TARGET_COND3_TYPE);
	myCombo12 = (CComboBox*) GetDlgItem(IDC_COMBO_TARGET_COND4_TYPE);
	myCombo13 = (CComboBox*) GetDlgItem(IDC_COMBO_TARGET_COND1_NAME);
	myCombo14 = (CComboBox*) GetDlgItem(IDC_COMBO_TARGET_COND2_NAME);
	myCombo15 = (CComboBox*) GetDlgItem(IDC_COMBO_TARGET_COND3_NAME);
	myCombo16 = (CComboBox*) GetDlgItem(IDC_COMBO_TARGET_COND4_NAME);
	myCheck = (CButton*) GetDlgItem(IDC_CHECK_DIRECT_ONLY);

	myCombo1->AddString("Type");
	myCombo1->AddString("Location");
	myCombo1->AddString("Name");
	myCombo2->AddString("Type");
	myCombo2->AddString("Location");
	myCombo2->AddString("Name");
	myCombo3->AddString("Type");
	myCombo3->AddString("Location");
	myCombo3->AddString("Name");
	myCombo4->AddString("Type");
	myCombo4->AddString("Location");
	myCombo4->AddString("Name");
	myCombo9->AddString("Type");
	myCombo9->AddString("Location");
	myCombo9->AddString("Name");
	myCombo10->AddString("Type");
	myCombo10->AddString("Location");
	myCombo10->AddString("Name");
	myCombo11->AddString("Type");
	myCombo11->AddString("Location");
	myCombo11->AddString("Name");
	myCombo12->AddString("Type");
	myCombo12->AddString("Location");
	myCombo12->AddString("Name");
	myCheck->SetCheck(1);

	myEdit = (CEdit*) GetDlgItem(IDC_EDIT_STEPS);
	myEdit->SetWindowText("9");

	myEdit = (CEdit*) GetDlgItem(IDC_EDIT_SIZE);
	myEdit->SetWindowText("70");

	LoadTypes(5);
	LoadTypes(13);

	for (i = 0; i < myCombo1->GetCount(); i++)
	{
		myCombo1->GetLBText(i, tempStr);

		if (tempStr == "Type")
		{
			myCombo1->SetCurSel(i);
		}
	}

	for (i = 0; i < myCombo5->GetCount(); i++)
	{
		myCombo5->GetLBText(i, tempStr);

		if (tempStr == "Ligand")
		{
			myCombo5->SetCurSel(i);
		}
	}
	for (i = 0; i < myCombo9->GetCount(); i++)
	{
		myCombo9->GetLBText(i, tempStr);

		if (tempStr == "Type")
		{
			myCombo9->SetCurSel(i);
		}
	}

	for (i = 0; i < myCombo13->GetCount(); i++)
	{
		myCombo13->GetLBText(i, tempStr);

		if (tempStr == "TF")
		{
			myCombo13->SetCurSel(i);
		}
	}

	//LoadTypes(5);
	//LoadTypes(13);

	//add and set conditions

	return TRUE;  // return TRUE unless you set the focus to a control
	// EXCEPTION: OCX Property Pages should return FALSE
}

void CDialogPathwayGeneratorSetup::OnCbnSelchangeComboSourceCond1Type()
{
	CComboBox* myCombo;
	int nIndex;
	myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_SOURCE_COND1_TYPE);

	nIndex = myCombo->GetCurSel();

	switch (nIndex)
	{
	case 1:
		LoadNames(5);
		break;
	case 2:
		LoadTypes(5);
		break;
	case 0:
		LoadLocations(5);
		break;
	default:
		LoadTypes(5);
		break;
	}

	myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_SOURCE_COND1_NAME);

	myCombo->SetCurSel(0);
}
void CDialogPathwayGeneratorSetup::LoadNames(int comboNum)
{
	MOLECULE* tempNode;
	tempNode = MoleculesList;
	CComboBox* myCombo;

	switch (comboNum)
	{
	case 5:
		myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_SOURCE_COND1_NAME);
		break;
	case 6:
		myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_SOURCE_COND2_NAME);
		break;
	case 7:
		myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_SOURCE_COND3_NAME);
		break;
	case 8:
		myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_SOURCE_COND4_NAME);
		break;
	case 13:
		myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_TARGET_COND1_NAME);
		break;
	case 14:
		myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_TARGET_COND2_NAME);
		break;
	case 15:
		myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_TARGET_COND3_NAME);
		break;
	case 16:
		myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_TARGET_COND4_NAME);
		break;
	}

	int size = myCombo->GetCount();
	int i;
	for (i = 0; i < size; i++)
	{
		myCombo->DeleteString(0);
	}

	myCombo->SetEditSel(0, -1);
	myCombo->Clear();

	while (tempNode)
	{	
		myCombo->AddString(tempNode->name);
		tempNode = tempNode->next;
	}
}
void CDialogPathwayGeneratorSetup::LoadTypes(int comboNum)
{
	MOLECULE* tempNode;
	MOLECULE* tempNode1;
	tempNode = MoleculesList;
	CComboBox* myCombo;
	int flag;

	switch (comboNum)
	{
	case 5:
		myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_SOURCE_COND1_NAME);
		break;
	case 6:
		myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_SOURCE_COND2_NAME);
		break;
	case 7:
		myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_SOURCE_COND3_NAME);
		break;
	case 8:
		myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_SOURCE_COND4_NAME);
		break;
	case 13:
		myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_TARGET_COND1_NAME);
		break;
	case 14:
		myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_TARGET_COND2_NAME);
		break;
	case 15:
		myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_TARGET_COND3_NAME);
		break;
	case 16:
		myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_TARGET_COND4_NAME);
		break;
	}
	
	int size = myCombo->GetCount();
	int i;
	for (i = 0; i < size; i++)
	{
		myCombo->DeleteString(0);
	}
	myCombo->SetEditSel(0, -1);
	myCombo->Clear();

	while (tempNode)
	{	
		tempNode1 = MoleculesList;
		flag = 0;
		while (tempNode1 != tempNode)
		{
			if (!strcmp(tempNode1->moleculeType, tempNode->moleculeType))
			{
				flag = 1;
				break;
			}
			tempNode1 = tempNode1->next;
		}
		if (!flag)
		{
			myCombo->AddString(tempNode->moleculeType);
		}
		tempNode = tempNode->next;
	}
}
void CDialogPathwayGeneratorSetup::LoadLocations(int comboNum)
{
	MOLECULE* tempNode;
	MOLECULE* tempNode1;
	tempNode = MoleculesList;
	CComboBox* myCombo;
	int flag;

	switch (comboNum)
	{
	case 5:
		myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_SOURCE_COND1_NAME);
		break;
	case 6:
		myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_SOURCE_COND2_NAME);
		break;
	case 7:
		myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_SOURCE_COND3_NAME);
		break;
	case 8:
		myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_SOURCE_COND4_NAME);
		break;
	case 13:
		myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_TARGET_COND1_NAME);
		break;
	case 14:
		myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_TARGET_COND2_NAME);
		break;
	case 15:
		myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_TARGET_COND3_NAME);
		break;
	case 16:
		myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_TARGET_COND4_NAME);
		break;
	}

	int size = myCombo->GetCount();
	int i;
	for (i = 0; i < size; i++)
	{
		myCombo->DeleteString(0);
	}
	myCombo->SetEditSel(0, -1);
	myCombo->Clear();

	while (tempNode)
	{	
		tempNode1 = MoleculesList;
		flag = 0;
		while (tempNode1 != tempNode)
		{
			if (!strcmp(tempNode1->location, tempNode->location))
			{
				flag = 1;
				break;
			}
			tempNode1 = tempNode1->next;
		}
		if (!flag)
		{
			myCombo->AddString(tempNode->location);
		}
		tempNode = tempNode->next;
	}
}
void CDialogPathwayGeneratorSetup::OnCbnSelchangeComboSourceCond2Type()
{
	CComboBox* myCombo;
	int nIndex;
	myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_SOURCE_COND2_TYPE);

	nIndex = myCombo->GetCurSel();

	switch (nIndex)
	{
	case 1:
		LoadNames(6);
		break;
	case 2:
		LoadTypes(6);
		break;
	case 0:
		LoadLocations(6);
		break;
	default:
		LoadTypes(6);
		break;
	}

	myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_SOURCE_COND2_NAME);

	myCombo->SetCurSel(0);
}

void CDialogPathwayGeneratorSetup::OnCbnSelchangeComboSourceCond3Type()
{
	CComboBox* myCombo;
	int nIndex;
	myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_SOURCE_COND3_TYPE);

	nIndex = myCombo->GetCurSel();

	switch (nIndex)
	{
	case 1:
		LoadNames(7);
		break;
	case 2:
		LoadTypes(7);
		break;
	case 0:
		LoadLocations(7);
		break;
	default:
		LoadTypes(7);
		break;
	}

	myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_SOURCE_COND3_NAME);

	myCombo->SetCurSel(0);
}

void CDialogPathwayGeneratorSetup::OnCbnSelchangeComboSourceCond4Type()
{
	CComboBox* myCombo;
	int nIndex;
	myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_SOURCE_COND4_TYPE);

	nIndex = myCombo->GetCurSel();

	switch (nIndex)
	{
	case 1:
		LoadNames(8);
		break;
	case 2:
		LoadTypes(8);
		break;
	case 0:
		LoadLocations(8);
		break;
	default:
		LoadTypes(8);
		break;
	}

	myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_SOURCE_COND4_NAME);

	myCombo->SetCurSel(0);
}

void CDialogPathwayGeneratorSetup::OnCbnSelchangeComboTargetCond1Type()
{
	CComboBox* myCombo;
	int nIndex;
	myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_TARGET_COND1_TYPE);

	nIndex = myCombo->GetCurSel();

	switch (nIndex)
	{
	case 1:
		LoadNames(13);
		break;
	case 2:
		LoadTypes(13);
		break;
	case 0:
		LoadLocations(13);
		break;
	default:
		LoadTypes(13);
		break;
	}

	myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_TARGET_COND1_NAME);

	myCombo->SetCurSel(0);
}

void CDialogPathwayGeneratorSetup::OnCbnSelchangeComboTargetCond2Type()
{
	CComboBox* myCombo;
	int nIndex;
	myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_TARGET_COND2_TYPE);

	nIndex = myCombo->GetCurSel();

	switch (nIndex)
	{
	case 1:
		LoadNames(14);
		break;
	case 2:
		LoadTypes(14);
		break;
	case 0:
		LoadLocations(14);
		break;
	default:
		LoadTypes(14);
		break;
	}

	myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_TARGET_COND2_NAME);

	myCombo->SetCurSel(0);
}

void CDialogPathwayGeneratorSetup::OnCbnSelchangeComboTargetCond3Type()
{
	CComboBox* myCombo;
	int nIndex;
	myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_TARGET_COND3_TYPE);

	nIndex = myCombo->GetCurSel();

	switch (nIndex)
	{
	case 1:
		LoadNames(15);
		break;
	case 2:
		LoadTypes(15);
		break;
	case 0:
		LoadLocations(15);
		break;
	default:
		LoadTypes(15);
		break;
	}

	myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_TARGET_COND3_NAME);

	myCombo->SetCurSel(0);
}

void CDialogPathwayGeneratorSetup::OnCbnSelchangeComboTargetCond4Type()
{
	CComboBox* myCombo;
	int nIndex;
	myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_TARGET_COND4_TYPE);

	nIndex = myCombo->GetCurSel();

	switch (nIndex)
	{
	case 1:
		LoadNames(16);
		break;
	case 2:
		LoadTypes(16);
		break;
	case 0:
		LoadLocations(16);
		break;
	default:
		LoadTypes(16);
		break;
	}

	myCombo = (CComboBox*) GetDlgItem(IDC_COMBO_TARGET_COND4_NAME);

	myCombo->SetCurSel(0);
}

void CDialogPathwayGeneratorSetup::OnCbnKillfocusComboSourceCond2Type()
{
	
}

void CDialogPathwayGeneratorSetup::OnBnClickedCancel()
{
	// TODO: Add your control notification handler code here
	OnCancel();
}
